package com.lavegue.common;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author: luoweibin
 * @date:2011-12-19
 * description: 
 * 分页对象的实体类
 */
public class Page<T> implements Serializable{

	//当前页数
	private int pageNo=1;
	//总记录数
	private int totalRecord;
	//内容
	private List<T> data;
	//起始记录数
	private int start;
	//每页多少条
	private int pageSize = 10;
	//总页数
	private int totalPage;
	//是否有下一页
	private boolean hasNextPage;
	//是否有上一页
	private boolean hasPrePage;
	//是否只有一页
	private boolean hasOnePage;
	
	private List listNum=null;//总页数list
	
	public List getListNum() {
		return listNum;
	}

	public void setListNum(List listNum) {
		this.listNum = listNum;
	}
	

	public Page(int pageNo, int totalRecord, List<T> data) {
		this.pageNo = pageNo;
		this.totalRecord = totalRecord;
		this.data = data;
		compute();
	}
	
	public Page(int pageNo, int totalRecord, List<T> data, int pageSize) {
		this.pageNo = pageNo;
		this.totalRecord = totalRecord;
		this.data = data;
		this.pageSize = pageSize;
		compute();
		if(totalPage>=1)
		{
		    listNum=new ArrayList();
			
			for(int i=1;i<=totalPage;i++)
			{
				listNum.add(i);
			}
		}
	}
	
	/**
	 * 计算分页的其他参数
	 */
	private void compute() {
		this.start = (this.pageNo - 1) * this.pageSize;
		this.totalPage = this.totalRecord/this.pageSize;
		if (this.totalRecord%this.pageSize != 0) {
			this.totalPage++;
		}
		if (this.pageNo < this.totalPage) {
			this.hasNextPage = true;
		}
		if (this.pageNo > 1) {
			this.hasPrePage = true;
		}
		if(this.totalRecord<=this.pageSize)
		{
			this.hasOnePage=true;
		}
	
		
	}
	
	public static int computeStart(int pageNo, int pageSize) {
		return (pageNo - 1) * pageSize;
	}

	public int getPageNo() {
		return pageNo;
	}

	public void setPageNo(int pageNo) {
		this.pageNo = pageNo;
	}

	public int getTotalRecord() {
		return totalRecord;
	}

	public void setTotalRecord(int totalRecord) {
		this.totalRecord = totalRecord;
	}

	public List<T> getData() {
		return data;
	}

	public void setData(List<T> data) {
		this.data = data;
	}

	public int getStart() {
		return start;
	}

	public void setStart(int start) {
		this.start = start;
	}

	public int getPageSize() {
		return pageSize;
	}

	public void setPageSize(int pageSize) {
		this.pageSize = pageSize;
	}

	public int getTotalPage() {
		return totalPage;
	}

	public void setTotalPage(int totalPage) {
		this.totalPage = totalPage;
	}

	public boolean isHasNextPage() {
		return hasNextPage;
	}

	public void setHasNextPage(boolean hasNextPage) {
		this.hasNextPage = hasNextPage;
	}

	public boolean isHasPrePage() {
		return hasPrePage;
	}

	public boolean isHasOnePage() {
		return hasOnePage;
	}

	public void setHasOnePage(boolean hasOnePage) {
		this.hasOnePage = hasOnePage;
	}

	public void setHasPrePage(boolean hasPrePage) {
		this.hasPrePage = hasPrePage;
	}
	
}
